﻿using System;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RaytracerLib;
using RaytracerLib.MathLib;
using RaytracerLib.Rays;

namespace RaytracerTest
{
    [TestClass]
    public class AABBTest : TestBase
    {
        [TestMethod]
        public void AABB_Test()
        {
            Scene scene = new Scene();

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 0.5, 0.5), new Vector3(-1, 0, 0));
                Assert.IsTrue(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 0.5, 0.5), new Vector3(-1, 0.1, 0.1));
                Assert.IsTrue(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 0.5, 0.5), new Vector3(1, 0, 0));
                Assert.IsFalse(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 1, 1), new Vector3(-1, 0, 0));
                Assert.IsFalse(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 
                    1 + Constants.DOUBLE_PRECISION, 1), new Vector3(-1, 0, 0));
                Assert.IsFalse(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 1 - Constants.DOUBLE_PRECISION, 
                    1 - Constants.DOUBLE_PRECISION), new Vector3(-1, 0, 0));
                Assert.IsTrue(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 0, 0), new Vector3(-1, -1, 0));
                Assert.IsFalse(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(2, 0.5, 0), new Vector3(-1, -1, 0));
                Assert.IsFalse(aabb.IsIntersecting(ray));
            }

            {
                AABB aabb = new AABB(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                CameraRay ray = new CameraRay(scene, new Vector3(0.5, 0.5, 0.5), new Vector3(-1, -1, 0));
                Assert.IsTrue(aabb.IsIntersecting(ray));
            }
        }
    }
}